#-*- codeing = utf-8 -*-
#@Time : 2020/7/31 14:46
#@Author : 阳某
#@File : resq.py
#@Software : PyCharm

import requests
# GET请求
# r = requests.get('http://httpbin.org/get')
# print(r.status_code,r.reason)
# print('GET请求:',r.text)

# POST请求
# r = requests.post('http://httpbin.org/post',data={'a':'1'})
# print('POST请求:',r.text)
# print('POST请求:',r.json())

# 带参数的GET请求
# r = requests.get('http://httpbin.org/get',params={'a':'1','b':'2','c':'3'})
# print('带参数的GET请求',r.json())

# 自定义headers的请求
# ua = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3775.400 QQBrowser/10.6.4208.400'
# headers={'User-Agent':ua}
# r = requests.get('http://httpbin.org/headers',headers = headers)
# print('自定义headers的请求:',r.json())

# 带cookies的请求
# cookies = dict(userid='123456',token='xxxxxxxxxxxxxxxxxx')
# r = requests.get('http://httpbin.org/cookies',cookies = cookies)
# print('带cookies的请求',r.json())

# Basic-auth 认证请求
# r = requests.get('http://httpbin.org/basic-auth/yangmou/123456',auth=('yangmou','123456'))
# print(r.text)
# print('Basic-auth 认证请求',r.json())

# 主动抛出状态码异常
# bad_r = requests.get('http://httpbin.org/status/404')
# print(bad_r.status_code)
# bad_r.raise_for_status()    #抛出异常

'''
# 使用requests，Session对象请求
# 创建一个session对象
s = requests.Session()
# session对象会保存服务器返回的set-cookies头信息里面的内容
s.get('http://httpbin.org/cookies/set/userid/123456')
s.get('http://httpbin.org/cookies/set/token/xxxxxxxxxxxxxx')
# print(type(s))
# print(s)
# 下一次请求会将本地的所有cookies信息自动添加到请求头信息里面
r = s.get('http://httpbin.org/cookies')
# print(type(r))
# print(r.text)
print('检查session中的cookies',r.json())
'''

# 在requests中使用代理
# r = requests.get('http://httpbin.org/ip')
# print('不使用代理：',r.json())
# r = requests.get('http://httpbin.org/ip',proxies = {'http':'http//iguye.com:41801'})
# print('使用代理：',r.json())

r =requests.get('http://httpbin.org/delay/4',timeout = 5)
print(r.text)




